﻿/*
// 


*/


#include "CmnFunc.h"

//---------------------for GetTickCount
#if defined( _WIN32 )
#include <Windows.h>
#endif	// _WIN32

#if defined( __linux__ )
#include <unistd.h>
#include <sys/time.h>
#include <netinet/in.h>
#endif
//---------------------for GetTickCount

#include <stdlib.h>
#include <time.h>

#include <stdlib.h>
#include <time.h>

dn_namespace_beg

float TransRadianToAngle(float Radian,bool IsRadianCCW,bool IsAngleCCW)
{
	float Angle = (Radian/PI)*180;
	if(IsRadianCCW!=IsAngleCCW)
	{
		Angle = -Angle;
	}
	return Angle;
}

int64 GetUSTick()
{
#if defined WIN32

    //  Get the high resolution counter's accuracy.
    LARGE_INTEGER ticksPerSecond;
    QueryPerformanceFrequency (&ticksPerSecond);

    //  What time is it?
    LARGE_INTEGER tick;
    QueryPerformanceCounter (&tick);

    //  Convert the tick number into the number of seconds
    //  since the system was started.
    double ticks_div =  ((double)ticksPerSecond.QuadPart / 1000000);     
    return (int64) (tick.QuadPart / ticks_div);

#elif LINUX

    //  Use POSIX gettimeofday function to get precise time.
    struct timeval tv;
    int rc = gettimeofday (&tv, NULL);
    errno_assert (rc == 0);
    return (tv.tv_sec * (int64) 1000000 + tv.tv_usec);

#endif
}


int64	GetMSTick()
{
	return GetUSTick()/1000;
}


static int rand_seed = 0;
int Rand(int Min, int Max)
{
	if(Min == Max)
		return Min;

	if(rand_seed == 0) {
		rand_seed = (int)time(0);
		srand(rand_seed);
	}

	int rand_num = rand();
	rand_seed = rand_num;

	int offset = rand_num%(abs(Max-Min)+1) ;
	return Min+offset;
}
	

dn_namespace_end


